package com.gome.ocean.service.authority.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.gome.ocean.dao.authority.RoleDAO;
import com.gome.ocean.dao.model.authority.Role;
import com.gome.ocean.service.authority.RoleService;

/**
 * Created by liuqingxia on 2016/6/1.
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDAO roleDAO;

    @Override
    public Long insertRole(Role role) {
        return roleDAO.insertRole(role);
    }

    @Override
    public boolean removeRole(Long id) {
        return roleDAO.removeRoleById(id) == 1;
    }

    @Override
    public boolean updateRole(Role role) {
        return roleDAO.updateRole(role) == 1;
    }

    @Override
    public Page<Role> findAllRoles(int pageNum, int pageSize) {
        return (Page<Role>) roleDAO.findAllRoles(new RowBounds(pageNum, pageSize));
    }

    @Override
    public Role findRoleById(Long id) {
        return roleDAO.findRoleById(id);
    }
    /**
     * 根据角色名称查询
     * */
	@Override
	public Role getRoleByRoleName(String roleName) {
		try {
			Map<String, Object> map = new HashMap<String,Object>();
			map.put("roleName", roleName);
			return roleDAO.getRoleByRoleName(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
     * 查询全部角色名称和id
     * */
	@Override
	public List<Role> getAllRoles() {
		try {
			List<Role> list = roleDAO.getAllRoles();
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
